#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":platform:clock"

def prepare(module, options):
    if not options[":target"].has_driver("clock:lpc"):
        return False

    module.depends(":platform:core")
    return True

def build(env):
    device = env[":target"]
    driver = device.get_driver("clock")

    properties = device.properties
    properties["target"] = target = device.identifier
    properties["driver"] = driver

    env.substitutions = properties
    env.outbasepath = "modm/src/modm/platform/clock"

    env.template("static.hpp.in")
    env.template("clock.cpp.in")
    env.template("clock.hpp.in")

    env.copy("pll_calculator.hpp")
    env.copy("common_clock.cpp")
    env.copy("../common/common_clock.hpp", "common_clock.hpp")
